package com.skyeyes.controller.user;


import com.alibaba.fastjson.JSON;
import com.skyeyes.entity.LocationBean;
import com.skyeyes.result.Result;
import com.skyeyes.service.LocationService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/user")
@Api(tags = "C端用户定位接口")
@Slf4j
public class LocationController {


    @Autowired
    private LocationService locationService;

    @PostMapping("/address/saveAddressLoc")
    @ResponseBody
    @ApiOperation("获得上传坐标信息")//@RequestParam List<LocationDTO> String location
    public Result getLocationData(@RequestParam Map<String,Object> map){//String user_id,@RequestBody List<LocationDTO> location

        log.info("user_id: {}",map.get("user_id"));
        log.info("location: {}",map.get("location"));
        List<LocationBean> locations = JSON.parseArray(map.get("location").toString(), LocationBean.class);
        if(locations!=null&&locations.size()>0){
            locationService.saveLocations(locations);

        }

        return Result.success();

    }

    @GetMapping("/address/locationtrace")
    @ResponseBody
    @ApiOperation("获得轨迹点")
    public Result getTrace(@RequestParam String user_id) {

        List<LocationBean> locationBeans=locationService.getLocationTrace(user_id);
        return Result.success(locationBeans);
    }
}
